package eclipse.weibo;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import weibo4j.User;
import weibo4j.Weibo;
import weibo4j.util.DebugPrn;

public class Activator extends AbstractUIPlugin {
    private static DebugPrn dp = new DebugPrn(Activator.class.getName());
    //public static final String CONSUMER_KEY = "1919370152";
    //public static final String CONSUMER_SECRET = "6b1262859159e4c56df6e4898506d8d0";//"pdos95";
    public static final String CONSUMER_KEY = "927543844";
    public static final String CONSUMER_SECRET = "604d053486275a4fa1e9df440f11ebd8";
    public static final String PLUGIN_ID = "eclipseweibo";
    private static Activator plugin;
    private static Weibo weibo = null;
    private static User login_user;
    private static User current_user;

    public static User getCurrent_user() {
        return current_user;
    }

    public static void setCurrent_user(User current_user) {
        Activator.current_user = current_user;
    }

    public static User getLogin_user() {
        return login_user;
    }

    public static void setLogin_user(User login_user) {
        Activator.login_user = login_user;
    }

    public static void setWeibo(Weibo weibo) {
        Activator.weibo = weibo;
    }

    public static Weibo getWeibo() {
        try{
        if (weibo == null) {
            System.setProperty("weibo4j.oauth.consumerKey", CONSUMER_KEY);
            System.setProperty("weibo4j.oauth.consumerSecret", CONSUMER_SECRET);
            weibo = new Weibo();
        }
        }catch(Throwable e){
            dp.error(e, e);
        }
        return weibo;
    }

    public static void delWeibo() {
        weibo = null;
    }

    public void start(BundleContext context) throws Exception {
        super.start(context);
        plugin = this;
    }

    public void stop(BundleContext context) throws Exception {
        plugin = null;
        super.stop(context);
    }

    public static Activator getDefault() {
        return plugin;
    }

    public static ImageDescriptor getImageDescriptor(String path) {
        return imageDescriptorFromPlugin("eclipseweibo", path);
    }

    public static boolean isShowImage() {
        IPreferenceStore ps = getDefault().getPreferenceStore();
        boolean b1 = ps.getBoolean("SHOWIMAGE");
        return (!(b1));
    }
}
